package com.hd.trans.framework.tools;

//import com.hudun.voicecovert.service.TTSService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by tony on 2016/3/10.
 */
public class ThreadPoolWrapper {

    private static ExecutorService FULL_TASK_EXECUTOR;
    private static ThreadPoolExecutor threadDownloadPool;
    private static ThreadPoolWrapper mInstance;


    public static ThreadPoolExecutor getThreadPool() {
        return threadDownloadPool;
    }

    private static ExecutorService LIMITED_TASK_EXECUTOR;  //限制线程个数的线程池

    public static ThreadPoolWrapper getInstance() {
        if (mInstance == null) {
            synchronized (ThreadPoolWrapper.class) {
                if (mInstance == null) {
                    mInstance = new ThreadPoolWrapper();
                }
            }
        }
        return mInstance;
    }

    public ThreadPoolWrapper() {
        FULL_TASK_EXECUTOR = Executors.newCachedThreadPool();
        LIMITED_TASK_EXECUTOR = Executors.newFixedThreadPool(10);
        threadDownloadPool = new ThreadPoolExecutor(6, 6,
                2L, TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>());
    }

    public void excuseThread(Runnable runnable) {
        FULL_TASK_EXECUTOR.execute(runnable);
    }

    public void shutdownThread() {
        FULL_TASK_EXECUTOR.shutdown();
    }

    public void excuseDownloadThread(Runnable runnable) {
        threadDownloadPool.execute(runnable);
    }


}
